package com.ggqq.day330;

import java.util.ArrayList;
import java.util.List;

public class Z {
    public static void main(String[] args) {
        Z z = new Z();
        System.out.println(z.convert("LEETCOD", 3));
    }
    public String convert(String s,int numRows){
        if(numRows<2){
            return s;
        }
        List<StringBuilder> rows = new ArrayList<StringBuilder>();//行列表
        for(int i=0;i<numRows;i++){
            rows.add(new StringBuilder());//新建numROWs行
        }
        int i=0,flag =-1;
        for(char c:s.toCharArray()){
            rows.get(i).append(c);   //将每个字符c填入对应的行
            if(i ==0 ||i == numRows-1){
                flag = -flag;//到达转折点，执行反向
            }
            i += flag; //更新行下标
        }
        StringBuilder res = new StringBuilder();
        for(StringBuilder row:rows){
            res.append(row);
        }
        return  res.toString();

    }
}
